<?php

class LesEntreprises {

    private $_nom;

    private function __construct() {
        $this->_nom = '';
    }

    public static function ajouterEntreprise($nomEntreprise, $adresseEntreprise, $nomContact, $courielContact, $themeStage, $periodeDebut, $periodeFin) {
        $sql = "INSERT INTO entreprise VALUES (NULL," . $_SESSION['id_utilisateur'] . ",'$nomEntreprise','$adresseEntreprise','$nomContact','$courielContact','$themeStage','$periodeDebut','$periodeFin')";
        
        echo $sql;

        $pdo = PdoSio::getPdoSio();
        $resultat = $pdo->requeteAction($sql);
        

        return $resultat;
        
    }

    public static function visualiserEntreprise() {
        $sql = "SELECT * FROM entreprise";

        $pdo = PdoSio::getPdoSio();
        $resultat = $pdo->requeteSelection($sql);
        // var_dump($resultat);
        return $resultat;
    }

    public static function obtenirLesMotsClesSousFormeDeBaliseSelectHTML($unIdDEntreprise) {
        $pdo = PdoSio::getPdoSio();

        $lesMotsCles = $pdo->requeteSelection("select * from mot_cle_stage where id_entreprise= $unIdDEntreprise");
        $laBaliseSelect = "<select size='2' class='input-medium'>";
        foreach ($lesMotsCles as $unTupleMotCle) {
            //je dois generer des <option .... 
            $idMotCle = $unTupleMotCle["id_mot_cle"];
            $libelleMotCle = $unTupleMotCle["libelle_mot_cle"];
            $laBaliseSelect .= "<option value='$idMotCle' >$libelleMotCle</option>";
        }
        $laBaliseSelect .="</select>";
        return $laBaliseSelect;
    }

    public static function ajouterUnMotCle($idEntreprise, $leMotCle) {
        $pdo = PdoSio::getPdoSio();
        $pdo->requeteAction("insert into mot_cle_stage values(null,$idEntreprise,'$leMotCle')");
    }
    
    public static function modifRecupEntreprise($idEntreprise){
        
        $pdo = PdoSio::getPdoSio();
        $resultat = $pdo->requeteSelection("SELECT * FROM entreprise WHERE idEntreprise=$idEntreprise");
        
        return $resultat[0];
    }
    
    public static function enregistrerModifEntreprise($nomEntreprise, $adresseEntreprise, $nomContact, $courielContact,$themeStage, $periodeDebut,$periodeFin, $idEntreprise){
        $pdo = PdoSio::getPdoSio();
        echo ("UPDATE entreprise SET nomEntreprise='$nomEntreprise', adresseEntreprise='$adresseEntreprise', nomContact='$nomContact', courielContact='$courielContact', themeStage='$themeStage', periodeDebut='$periodeDebut', periodeFin='$periodeFin' WHERE idEntreprise=$idEntreprise");
        $resultat = $pdo->requeteAction("UPDATE entreprise SET nomEntreprise='$nomEntreprise', adresseEntreprise='$adresseEntreprise', nomContact='$nomContact', courielContact='$courielContact', themeStage='$themeStage', periodeDebut='$periodeDebut', periodeFin='$periodeFin' WHERE idEntreprise=$idEntreprise");
         
    }
    
    public static function recherchemotcle($recherche){
        
        $pdo=  PdoSio::getPdoSio();
        //echo $recherche;
        //echo("SELECT * FROM entreprise e,mot_cle_stage m WHERE e.idEntreprise=idEntreprise AND libelle_mot_cle like'%$recherche%'  ");
        $resultat=$pdo->requeteSelection("SELECT * FROM entreprise e,mot_cle_stage m WHERE e.idEntreprise = m.id_entreprise AND m.libelle_mot_cle LIKE'%$recherche%' group by id_utilisateur");
        //echo("SELECT * FROM entreprise e,mot_cle_stage m WHERE e.idEntreprise = m.id_entreprise AND m.libelle_mot_cle LIKE'%$recherche%' group by id_utilisateur");
        return $resultat;
        
    }
    
    public static function rechercheAnnee($recherche){
        $pdo = PdoSio::getPdoSio();
        //echo ("SELECT * FROM entreprise WHERE periodeDebut LIKE '%$recherche%' OR periodeFin LIKE '%$recherche%'");
        $resultat = $pdo->requeteSelection("SELECT * FROM entreprise WHERE periodeDebut LIKE '%$recherche%' OR periodeFin LIKE '%$recherche%'");
        return $resultat;
    }

}
